/*
 * Copyright (C) 2012 rothens
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package rpg.util.yaml;

/**
 *
 * @author rothens
 */
public class Version {

    public final int major;
    public final int minor;

    public Version(String value) {
        if (value == null) {
            throw new IllegalArgumentException("Value can't be null.");
        }
        int d = value.indexOf('.');
        if (d == -1) {
            throw new IllegalArgumentException("It must contain a period.");
        }
        major = Integer.parseInt(value.substring(0, d));
        minor = Integer.parseInt(value.substring(d + 1));
    }

    public Version(int major, int minor) {
        this.major = major;
        this.minor = minor;
    }

    @Override
    public String toString() {
        return major + "." + minor;
    }

    public boolean equals(int minor, int major) {
        return this.minor == minor && this.major == major;
    }

    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Version other = (Version) obj;
        return major == other.major && minor == other.minor;
    }
}
